<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>内容管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link href="/lobsteruiframe/layuiadmin/layui/css/layui.css" rel="stylesheet" />
    <link href="/lobsteruiframe/layuiadmin/style/admin.css" rel="stylesheet" />
    <script src="/lobsteruiframe/layuiadmin/layui/layui.js"></script>
    <script src="/jslib/jquery-3.4.1.min.js"></script>
    <script src="/jslib/lobster.js"></script>

</head>

<body>
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-row">
                    <div class="layui-inline">
                        <div class="layui-form-item">
                            <label class="layui-form-label">关键词：</label>
                            <div class="layui-input-inline" style="width:140px">
                                <input class="layui-input" type="text" autocomplete="off" name="Key" id="Key" />
                            </div>
                        </div>
                    </div>
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="query-submit">
                        <i class="layui-icon layuiadmin-button-btn layui-icon-search"></i>查询
                    </button>
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="add-submit">
                        <i class="layui-icon layuiadmin-button-btn layui-icon-add"></i>添加新项
                    </button>
                </div>
            </div>
            <div class="layui-card-body">
                <table id="ContList" lay-filter="ContList"></table>
            </div>
        </div>
    </div>
    <!--操作按钮-->
    <script type="text/html" id="useroption">
        <a class="layui-btn  layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
        {{# if(d.Status==99){ }}
        <a class="layui-btn  layui-btn-xs layui-btn-warm"
            lay-event="release2"><i class="layui-icon layui-icon-edit"></i>取消发布</a>

        {{# }else { }}
        <a class="layui-btn  layui-btn-xs layui-btn-warm"
            lay-event="release"><i class="layui-icon layui-icon-edit"></i>立即发布</a>
        {{# } }}
        <a class="layui-btn  layui-btn-xs layui-btn-warm"
            lay-event="dele"><i class="layui-icon layui-icon-edit"></i>删除</a>
    </script>
    <script type="text/html" id="titleTpl">
        {{# if(d.IsHot){ }}
        <span class="layui-icon layui-icon-fire" style="color:red;"></span>
        {{# } }}

        {{# if(d.PicPath){ }}
        <span class="layui-icon layui-icon-picture" style="color:#009688;"></span>
        {{# } }}
        <span>{{d.Title}}</span>
    </script>
    <script type="text/html" id="flagTpl">
        {{# if(d.Status == 99){ }}
        <span style="color:#009688">已发布</span>
        {{# } else if(d.AuditStatus == 0) { }}
        <span style="color:#666;">草稿</span>
        {{# } else if(d.IsExpectPublish==true||d.IsExpectPublish == 1) { }}
        <span style="color:#009688;">预期发布</span>
        {{# } else if(d.Status == 98) { }}
        <span style="color:#5FB878;">已修改</span>
        {{# }else{ }}
        <span>待发布</span>
        {{# } }}
    </script>
    <script type="text/html" id="flagfb">
        {{# if(d.Status == 99){ }}
        <span>{{d.ReleaseTime}}</span>
        {{# }else{ }}
        <span></span>
        {{# } }}
    </script>

</body>

</html>
<script type="text/javascript">
    lobsterlayui.main(['index', 'layer', 'form', 'element', 'table'],{
		data: {
			$layui: null,
			search: {
                key: "",
                nid: 0,
            },
            node: {},
            table: null
		},
		pageload: function (right) {
			var query = location.search;
            if (query) {
                query = query.substr(1);
                query.split('&').forEach(item => {
                    if (item.split('=')[0] == "nid") {
                        this.data.search.nid = parseInt(item.split("=")[1]);
                    }
                });
            }
            this.loadList();
            this.initEvent();
		},

        //初始化事件
            initEvent: function () {
                var self = this;
                layui.table.on("tool(ContList)", obj => {
                    let data = obj.data;
                    let layEvent = obj.event;
                    if (layEvent == "edit") {
                        parent.layui.layer.open({
                            type: 2
                            , title: '内容编辑'
                            , closeBtn: 0//不显示右上角关闭按钮
                            , content: 'edit.html?nid=' + this.data.search.nid + "&cid=" + data.CID+"&appid="+lobsterlayui.GetAppId()
                            , area: ['100%', '100%']  //宽，高
                            , btn: ["保存内容", "取消"],
                            yes: function (index, layero) {
                                var iframeWin = window[layero.find('iframe')[0]['name']]
                                    , submit = layero.find('iframe').contents().find('button[lay-submit]');
                                console.log(self);
                                layero.find('iframe')[0].contentWindow.submitSuccess = function () {
                                    console.log(self);
                                    //成功之后执行的方法
                                    self.data.table.reload();
                                }
                                console.log(submit);
                                submit.trigger('click');
                            }
                        });
                    } else if (layEvent == "release") {
                        layer.confirm('确认发布此内容?', { icon: 3, title: '提示' }, function (index) {
                            self.updateState(data.CID, 99);
                            layer.close(index);
                        }, function (index) {
                            layer.close(index);
                        });

                    } else if (layEvent == "release2") {
                        layer.confirm('确认取消此内容的发布?', { icon: 3, title: '提示' }, function (index) {
                            self.updateState(data.CID, 0);
                            layer.close(index);
                        }, function (index) {
                            layer.close(index);
                        });
                    }
                    else if (layEvent == "dele") {

                        layer.confirm('确认删除此内容?', { icon: 3, title: '提示' }, function (index) {
                            self.delete(data.CID);
                            layer.close(index);
                        }, function (index) {
                            layer.close(index);
                        });

                    } else if (layEvent == "review") {
                        parent.layui.layer.open({
                            type: 2
                            , title: '版本浏览'
                            , closeBtn: 0//不显示右上角关闭按钮
                            , content: 'VersionList.html?nid=' + this.data.search.nid + "&cid=" + data.CID+"&appid="+lobsterlayui.GetAppId()
                            , area: ['800px', '90%']  //宽，高
                            , btn: ["关闭"],
                            yes: function (index, layero) {
                                parent.layui.layer.close(index);
                            }
                        });
                    }

                });
                layui.form.on('submit(add-submit)', data => {
                    parent.layui.layer.open({
                        type: 2
                        , title: '内容添加'
                        , closeBtn: 0//不显示右上角关闭按钮
                        , content: 'edit.html?nid=' + this.data.search.nid+"&appid="+lobsterlayui.GetAppId()
                        , area: ['100%', '100%']  //宽，高
                        , btn: ["保存内容", "取消"],
                        yes: function (index, layero) {
                            var iframeWin = window[layero.find('iframe')[0]['name']]
                                , submit = layero.find('iframe').contents().find('button[lay-submit]');
                            console.log(layero.find('iframe'))
                            layero.find('iframe')[0].contentWindow.submitSuccess = function () {

                                //成功之后执行的方法
                                self.data.table.reload();
                            }
                            console.log(submit);
                            submit.trigger('click');
                        }
                    });
                })
                layui.form.on('submit(query-submit)', data => {
                    this.loadList();
                });
            },
            //修改状态
            updateState: function (cid, state) {
                lobsterlayui.GETAPI('tsAdmin.updatecontextstate',{cid: cid, state: state}).then(retdata=>{
                    this.data.table.reload();
                })
            },
            //删除
            delete: function (id) {
                lobsterlayui.GETAPI('tsAdmin.deletecontext',{cid: id}).then(retdata=>{
                    this.data.table.reload();
                })
            },
            //加载数据
            loadList: function () {
                if (this.data.table) {
                    this.data.search.key = $("#Key").val();
                    this.data.table.reload({
                        where: this.data.search
                        , page: {
                            curr: 1 //重新从第 1 页开始
                        }
                    })
                } else {
                    this.data.table = layui.table.render({
                        elem: "#ContList",
                        headers: lobsterlayui.GetHeaderData(),
                        where: this.data.search,
                        height: 'full-140',
                        //limit: 20,
                        url: lobsterlayui.GetLowCodeUrl("tsAdmin.getcontentlist"),
                        page: true,
                        even: true,
                        cols: [[
                            { field: 'CID', title: '编号', align: 'center', width: '80' },
                            { title: '标题', width: '500', templet: "#titleTpl" },
                            { field: 'Status', title: '状态', width: '100', align: 'center', templet: '#flagTpl' },
                            { field: 'ReleaseTime', title: '发布时间', width: '170', sort: true, align: 'center', templet: '#flagfb' },
                            // { field: 'ExpectPublishTime', title: '预期发布时间', width: '170', sort: true, align: 'center', templet: '#flagfb2' },
                            { field: 'AddTime', title: '添加时间', width: '170', sort: true, align: 'center', },
                            // { field: 'AddEmpName', title: '添加人', width: '150', sort: true, align: 'center', },

                            { title: '操作', fixed: 'right', toolbar: '#useroption', width: '350' }  //操作script的id 

                        ]],
                        parseData: function (res) {
                            return {
                                code: res.code,
                                msg: res.msg,
                                count: res.data.count,
                                data: res.data.list
                            }
                        }

                    });
                }
            },
        
    })

</script>